﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;//请先添加引用


namespace OracleDAL.Common
{
    /// <summary>
	/// 数据访问类DXT_INDIVIDUAL_CALL_H。
	/// </summary>
	public class DXT_INDIVIDUAL_CALL_H
	{
		public DXT_INDIVIDUAL_CALL_H()
		{}
		#region  成员方法

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string NE_ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from DXT_INDIVIDUAL_CALL_H");
			strSql.Append(" where NE_ID=:NE_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":NE_ID", OracleType.VarChar,50)};
			parameters[0].Value = NE_ID;

			return OracleHelper.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(Model.Common.DXT_INDIVIDUAL_CALL_H model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into DXT_INDIVIDUAL_CALL_H(");
			strSql.Append("NE_ID,EQUIP_NAME,INDEX_NUM,NEW_TIME_CODE,HOOK_CALL_SUCC_CONN_COUNT,DIRECT_CALL_SUCC_CONN_COUNT,DUPLEX_CALL_SUCC_CONN_COUNT,START_TIME,STOP_TIME)");
			strSql.Append(" values (");
			strSql.Append(":NE_ID,:EQUIP_NAME,:INDEX_NUM,:NEW_TIME_CODE,:HOOK_CALL_SUCC_CONN_COUNT,:DIRECT_CALL_SUCC_CONN_COUNT,:DUPLEX_CALL_SUCC_CONN_COUNT,:START_TIME,:STOP_TIME)");
			OracleParameter[] parameters = {
					new OracleParameter(":NE_ID", OracleType.VarChar,16),
					new OracleParameter(":EQUIP_NAME", OracleType.VarChar,100),
					new OracleParameter(":INDEX_NUM", OracleType.Number,4),
					new OracleParameter(":NEW_TIME_CODE", OracleType.DateTime),
					new OracleParameter(":HOOK_CALL_SUCC_CONN_COUNT", OracleType.Float,22),
					new OracleParameter(":DIRECT_CALL_SUCC_CONN_COUNT", OracleType.Float,22),
					new OracleParameter(":DUPLEX_CALL_SUCC_CONN_COUNT", OracleType.Float,22),
					new OracleParameter(":START_TIME", OracleType.DateTime),
					new OracleParameter(":STOP_TIME", OracleType.DateTime)};
			parameters[0].Value = model.NE_ID;
			parameters[1].Value = model.EQUIP_NAME;
			parameters[2].Value = model.INDEX_NUM;
			parameters[3].Value = model.NEW_TIME_CODE;
			parameters[4].Value = model.HOOK_CALL_SUCC_CONN_COUNT;
			parameters[5].Value = model.DIRECT_CALL_SUCC_CONN_COUNT;
			parameters[6].Value = model.DUPLEX_CALL_SUCC_CONN_COUNT;
			parameters[7].Value = model.START_TIME;
			parameters[8].Value = model.STOP_TIME;

			OracleHelper.ExecuteSql(strSql.ToString(),parameters);
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public void Update(Model.Common.DXT_INDIVIDUAL_CALL_H model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update DXT_INDIVIDUAL_CALL_H set ");
			strSql.Append("NE_ID=:NE_ID,");
			strSql.Append("EQUIP_NAME=:EQUIP_NAME,");
			strSql.Append("INDEX_NUM=:INDEX_NUM,");
			strSql.Append("NEW_TIME_CODE=:NEW_TIME_CODE,");
			strSql.Append("HOOK_CALL_SUCC_CONN_COUNT=:HOOK_CALL_SUCC_CONN_COUNT,");
			strSql.Append("DIRECT_CALL_SUCC_CONN_COUNT=:DIRECT_CALL_SUCC_CONN_COUNT,");
			strSql.Append("DUPLEX_CALL_SUCC_CONN_COUNT=:DUPLEX_CALL_SUCC_CONN_COUNT,");
			strSql.Append("START_TIME=:START_TIME,");
			strSql.Append("STOP_TIME=:STOP_TIME");
			strSql.Append(" where NE_ID=:NE_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":NE_ID", OracleType.VarChar,16),
					new OracleParameter(":EQUIP_NAME", OracleType.VarChar,100),
					new OracleParameter(":INDEX_NUM", OracleType.Number,4),
					new OracleParameter(":NEW_TIME_CODE", OracleType.DateTime),
					new OracleParameter(":HOOK_CALL_SUCC_CONN_COUNT", OracleType.Float,22),
					new OracleParameter(":DIRECT_CALL_SUCC_CONN_COUNT", OracleType.Float,22),
					new OracleParameter(":DUPLEX_CALL_SUCC_CONN_COUNT", OracleType.Float,22),
					new OracleParameter(":START_TIME", OracleType.DateTime),
					new OracleParameter(":STOP_TIME", OracleType.DateTime)};
			parameters[0].Value = model.NE_ID;
			parameters[1].Value = model.EQUIP_NAME;
			parameters[2].Value = model.INDEX_NUM;
			parameters[3].Value = model.NEW_TIME_CODE;
			parameters[4].Value = model.HOOK_CALL_SUCC_CONN_COUNT;
			parameters[5].Value = model.DIRECT_CALL_SUCC_CONN_COUNT;
			parameters[6].Value = model.DUPLEX_CALL_SUCC_CONN_COUNT;
			parameters[7].Value = model.START_TIME;
			parameters[8].Value = model.STOP_TIME;

			OracleHelper.ExecuteSql(strSql.ToString(),parameters);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public void Delete(string NE_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from DXT_INDIVIDUAL_CALL_H ");
			strSql.Append(" where NE_ID=:NE_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":NE_ID", OracleType.VarChar,50)};
			parameters[0].Value = NE_ID;

			OracleHelper.ExecuteSql(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Model.Common.DXT_INDIVIDUAL_CALL_H GetModel(string NE_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select NE_ID,EQUIP_NAME,INDEX_NUM,NEW_TIME_CODE,HOOK_CALL_SUCC_CONN_COUNT,DIRECT_CALL_SUCC_CONN_COUNT,DUPLEX_CALL_SUCC_CONN_COUNT,START_TIME,STOP_TIME from DXT_INDIVIDUAL_CALL_H ");
			strSql.Append(" where NE_ID=:NE_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":NE_ID", OracleType.VarChar,50)};
			parameters[0].Value = NE_ID;

			Model.Common.DXT_INDIVIDUAL_CALL_H model=new Model.Common.DXT_INDIVIDUAL_CALL_H();
			DataSet ds=OracleHelper.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				model.NE_ID=ds.Tables[0].Rows[0]["NE_ID"].ToString();
				model.EQUIP_NAME=ds.Tables[0].Rows[0]["EQUIP_NAME"].ToString();
				if(ds.Tables[0].Rows[0]["INDEX_NUM"].ToString()!="")
				{
					model.INDEX_NUM=int.Parse(ds.Tables[0].Rows[0]["INDEX_NUM"].ToString());
				}
				if(ds.Tables[0].Rows[0]["NEW_TIME_CODE"].ToString()!="")
				{
					model.NEW_TIME_CODE=DateTime.Parse(ds.Tables[0].Rows[0]["NEW_TIME_CODE"].ToString());
				}
				if(ds.Tables[0].Rows[0]["HOOK_CALL_SUCC_CONN_COUNT"].ToString()!="")
				{
					model.HOOK_CALL_SUCC_CONN_COUNT=decimal.Parse(ds.Tables[0].Rows[0]["HOOK_CALL_SUCC_CONN_COUNT"].ToString());
				}
				if(ds.Tables[0].Rows[0]["DIRECT_CALL_SUCC_CONN_COUNT"].ToString()!="")
				{
					model.DIRECT_CALL_SUCC_CONN_COUNT=decimal.Parse(ds.Tables[0].Rows[0]["DIRECT_CALL_SUCC_CONN_COUNT"].ToString());
				}
				if(ds.Tables[0].Rows[0]["DUPLEX_CALL_SUCC_CONN_COUNT"].ToString()!="")
				{
					model.DUPLEX_CALL_SUCC_CONN_COUNT=decimal.Parse(ds.Tables[0].Rows[0]["DUPLEX_CALL_SUCC_CONN_COUNT"].ToString());
				}
				if(ds.Tables[0].Rows[0]["START_TIME"].ToString()!="")
				{
					model.START_TIME=DateTime.Parse(ds.Tables[0].Rows[0]["START_TIME"].ToString());
				}
				if(ds.Tables[0].Rows[0]["STOP_TIME"].ToString()!="")
				{
					model.STOP_TIME=DateTime.Parse(ds.Tables[0].Rows[0]["STOP_TIME"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select NE_ID,EQUIP_NAME,INDEX_NUM,NEW_TIME_CODE,HOOK_CALL_SUCC_CONN_COUNT,DIRECT_CALL_SUCC_CONN_COUNT,DUPLEX_CALL_SUCC_CONN_COUNT,START_TIME,STOP_TIME ");
			strSql.Append(" FROM DXT_INDIVIDUAL_CALL_H ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
            strSql.Append(" order by NE_ID,NEW_TIME_CODE");
			return OracleHelper.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "DXT_INDIVIDUAL_CALL_H";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return OracleHelper.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  成员方法
	}
}

